package top.gokzzz.mock.entity;

import top.gokzzz.log.annotation.DomainLog;
import top.gokzzz.log.listener.SysDomainLogListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

@Entity
@Table(name = "STAFF")
@DomainLog
@EntityListeners(SysDomainLogListener.class)
@NamedEntityGraphs(value = {@NamedEntityGraph(name = "detail",attributeNodes = {@NamedAttributeNode(value = "positions"),@NamedAttributeNode(value = "department")})})
public class Staff implements Serializable {
    private static final long serialVersionUID = 1761578631733574178L;

    public enum Gender {
        MALE,
        FEMALE,
        UNKNOWN;
    }

    @Id
    @Column(name = "ID", length = 36)
    private String id;

    @Column(name = "CODE")
    private String code;

    @Column(name = "NAME")
    private String name;

    @Enumerated(EnumType.STRING)
    @Column(name = "GENDER")
    private Gender gender;

    @Column(name = "MOBILE")
    private String mobile;

    @Column(name = "EMAIL")
    private String email;

    @Column(name = "ADDRESS")
    private String address;

    @Column(name = "BIRTHDAY")
    private LocalDate birthday;

    @ManyToOne
    @JoinColumn(name = "DEPARTMENT_ID", referencedColumnName = "ID")
    private Department department;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "STAFF_POSITION",
            joinColumns = {@JoinColumn(name = "STAFF_ID", referencedColumnName = "ID")},
            inverseJoinColumns = {@JoinColumn(name = "POSITION_ID", referencedColumnName = "ID")})
    private List<Position> positions;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public List<Position> getPositions() {
        return positions;
    }

    public void setPositions(List<Position> positions) {
        this.positions = positions;
    }
}
